<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { trainingList, trainingDel } from "@/http/api";

export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tableData: [],
      typeArr: [],
      schoolArr: [],
      queryData: {
        training_person: "",
        training_name: "",
        training_school_name: "",
        training_type: "",
        page: 1,
        per_page: 10,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    deleteFn(row) {
      ElMessageBox.confirm("确定删除选择的培训吗?", "删除提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        const { data } = await trainingDel({
          training_content_id: row.training_content_id,
        });
        if (data.code == 1) {
          ElMessage({
            type: "success",
            message: "删除成功",
          });
          this.getData();
        }
      });
    },
    getData() {
      trainingList(this.queryData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
    detailFn(row) {
      this.$router.push({
        path: "/sendTrainDetail",
        query: { id: row.training_content_id, page: this.queryData.page },
      });
    },
  },
  mounted() {},
  async created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.getData();
    this.schoolArr = await this.$getCate.getSchoolList();
    this.typeArr = await this.$getCate.getCateFn(10);
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>培训列表（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.training_person"
                placeholder="请输入发布账号"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.training_name"
                placeholder="请输入项目名称"
              />
            </el-form-item>
            <el-form-item>
              <el-select
                @change="getData"
                v-model="queryData.training_school_name"
                filterable
                clearable
                placeholder="请输入培训学校"
              >
                <el-option
                  v-for="item in schoolArr"
                  :key="item.school_id"
                  :label="item.school_name"
                  :value="item.school_name"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select
                @change="getData"
                clearable
                v-model="queryData.training_type"
                placeholder="请选择培训类型"
              >
                <el-option
                  v-for="item in typeArr"
                  :key="item.name"
                  :label="item.name"
                  :value="item.name"
                />
              </el-select>
            </el-form-item>

            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="training_name"
          show-overflow-tooltip
          width="150"
          label="项目名称"
        />
        <el-table-column
          prop="training_type"
          show-overflow-tooltip
          label="项目类别"
        />
        <el-table-column
          prop="total_money"
          show-overflow-tooltip
          label="培训价格"
        />
        <el-table-column
          prop="bm_money"
          show-overflow-tooltip
          label="报名定金"
        />
        <el-table-column
          prop="training_school_name"
          show-overflow-tooltip
          width="200"
          label="培训学校"
        />
        <el-table-column
          prop="training_people"
          show-overflow-tooltip
          label="培训人数"
        />
        <el-table-column
          prop="report_time"
          width="120"
          show-overflow-tooltip
          label="报道时间"
        />
        <el-table-column
          prop="training_time"
          show-overflow-tooltip
          label="培训时长"
        />
        <el-table-column width="100" show-overflow-tooltip label="项目状态">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag v-if="row.training_content_status == 1">报名中</el-tag>
              <el-tag type="info" v-if="row.training_content_status == 2"
                >报名中</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="training_person"
          show-overflow-tooltip
          label="发布账号"
        />
        <el-table-column prop="Name" width="120" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div class="greenText ctrlText" @click="detailFn(row)">详情</div>
              <div class="redText ctrlText" @click="deleteFn(row)">删除</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
